﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Bongiozzo
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }

        public override string GetVaryByCustomString(HttpContext context, string arg)
        {
            if (arg.ToLower() == "lang")
            {
                string langParam = context.Request.QueryString["lang"];
                HttpCookie langCookie = context.Request.Cookies["lang"];

                if (langParam != null)
                    return langParam == "ru" ? "ru" : "en";
                else
                    if (langCookie != null)
                        return langCookie.Value == "ru" ? "ru" : "en";
                return "";
            }
            return base.GetVaryByCustomString(context, arg);
        }

     }
}